<template>
  <div class="header">
    <span>西安</span>

    <van-popover
      v-model="showPopover"
      trigger="click"
      :actions="actions"
      @select="onSelect"
    >
      <template #reference>
        <van-search
          v-model="value"
          placeholder="请输入搜索关键词"
          background="#fd6664"
          autofocus
          shape="round"
          class="topinput"
          @search="enter"
        />
      </template>
    </van-popover>

    <router-link to="/login" tag="span" v-if="!mytoken">登录</router-link>
    <router-link to="/mine" tag="span" v-if="mytoken">我的</router-link>
    <router-view></router-view>
  </div>
</template>

<script>
import Vue from "vue";
import { Hotword} from "../../api/kinds";
import { Search, Popover } from "vant";
Vue.use(Search);
Vue.use(Popover);
export default {
  data() {
    return {
      value: "",
      mytoken: localStorage.getItem("token"),
      showPopover: false,
      actions: [],
    };
  },
  created() {
    Hotword().then((data) => {
      console.log(data.data.data);
      data.data.data.forEach(item => {
        if(item.keyword){
          this.actions.push({text:item.keyword})
        }
      });
      console.log(this.actions);
    });
  },
  methods: {
    enter() {
      this.$router.push("/search/" + this.value);
    },
    onSelect(action) {
      this.value=action.text
      this.enter()
    },
  },
};
</script>

<style scoped>
.header {
  display: flex;
  color: white;
  background-color: #fd6664;
  /* border-bottom: #87cdec solid .03125rem; */
  justify-content: space-around;
  align-items: center;
}
.topinput {
  height: 100%;
}
</style>